{	Problem: http://codeforces.ru/problemset/problem/4/C
 	Verdict: Accepted
}
type data=record
    s:string;
    n:longint;
end;
var n,i,k,j:longint; a:array[1..100010] of data; t:string; f:boolean;
begin
readln(n);
k:=0;
for i:=1 to n do begin
    readln(t);
    f:=true;
    for j:=1 to k do begin
        if a[j].s=t then begin
            f:=false;
            inc(a[j].n);
            writeln(t,a[j].n-1);
            break;        
        end;
    end;
    if f then begin
        writeln('OK');
        inc(k);
        a[k].s:=t;
        a[k].n:=1;
    end;
end;
end.